package com.mcms.service.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.mcms.util.MapUtil;
import com.mcms.web.vo.DWZResult;

public class DealResult {

	
	/**
	 * 处理提交结果，成功：清空所有信息；失败：所有信息保留
	 * 
	 * @param request
	 * @param isSuc
	 */
	public static void execute(HttpServletRequest request,boolean isSuc){
		System.out.println("=============DealResult==================");
		
		DWZResult dwzResult = new DWZResult();//"message":"操作成功", "navTabId":"navNewsLi", "forwardUrl":"", "callbackType":"closeCurrent"}
		String statusCode = "200";// 成功
		if(!isSuc){
			statusCode = "300";// 失败
		}
		dwzResult.setStatusCode(statusCode);
		dwzResult.setCallbackType((String)request.getAttribute("callBackType")==null?"":(String)request.getAttribute("callBackType"));// closeCurrent forward 
		dwzResult.setForwardUrl((String)request.getAttribute("forwardUrl")==null?"":(String)request.getAttribute("forwardUrl"));// callback时才有值 
		dwzResult.setMessage((String)request.getAttribute("message")==null?"":(String)request.getAttribute("message"));
		dwzResult.setNavTabId((String)request.getAttribute("tabId")==null?"":(String)request.getAttribute("tabId"));
		
//		dwzResult.setCallbackType("closeCurrent");  
//		dwzResult.setForwardUrl("customList.html?userName=aaa&deptCode=sc&actionType=listCustom");
//		dwzResult.setForwardUrl(); 
		
		request.setAttribute("dwzResult", dwzResult);
	}
	
	/**
	 * 处理提交结果，成功：清空所有信息；失败：所有信息保留
	 * 
	 * @param request
	 * @param isSuc
	 */
	public static DWZResult executeForMap(Map paramMap,boolean isSuc){
		System.out.println("=============DealResult==================");
		
		DWZResult dwzResult = new DWZResult();//"message":"操作成功", "navTabId":"navNewsLi", "forwardUrl":"", "callbackType":"closeCurrent"}
		String statusCode = "200";// 成功
		if(!isSuc){
			statusCode = "300";// 失败
		}
		dwzResult.setStatusCode(statusCode);
		dwzResult.setCallbackType(MapUtil.getString(paramMap, "callBackType"));// closeCurrent forward 
		dwzResult.setForwardUrl(MapUtil.getString(paramMap, "forwardUrl"));// callback时才有值 
		dwzResult.setMessage(MapUtil.getString(paramMap, "message"));
		dwzResult.setNavTabId(MapUtil.getString(paramMap, "tabId"));
		
//		dwzResult.setCallbackType("closeCurrent");  
//		dwzResult.setForwardUrl("customList.html?userName=aaa&deptCode=sc&actionType=listCustom");
//		dwzResult.setForwardUrl(); 
		
		return dwzResult;
	}	
}
